<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.ordCode" placeholder="订单号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.phone" placeholder="手机号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-date-picker
          format="yyyy-MM-dd HH:mm:ss"
          v-model="dataForm.dateTime"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" border v-loading="dataListLoading" style="width: 100%">
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="淘酒店ID">
              <span>{{ props.row.shid }}</span>
            </el-form-item>
            <el-form-item label="三方编码">
              <span>{{ props.row.hotelCode }}</span>
            </el-form-item>
            <el-form-item label="房型编码">
              <span>{{ props.row.roomCode }}</span>
            </el-form-item>
            <el-form-item label="房型名称">
              <span>{{ props.row.roomName }}</span>
            </el-form-item>
            <el-form-item label="价格政策">
              <span>{{ props.row.rateplanCode }}</span>
            </el-form-item>
            <el-form-item label="政策名称">
              <span>{{ props.row.rpName }}</span>
            </el-form-item>
            <el-form-item label="订单金额">
              <span>{{ props.row.payPrice }}</span>
            </el-form-item>
            <el-form-item label="采购金额">
              <span>{{ props.row.buyOrderPrice }}</span>
            </el-form-item>
            <el-form-item label="酒店渠道">
              <span>{{ props.row.plantfrom }}</span>
            </el-form-item>
            <el-form-item label="到店时间">
              <span>{{ props.row.earliestTime }}</span>
            </el-form-item>
            <el-form-item label="邮箱">
              <span>{{ props.row.email }}</span>
            </el-form-item>
            <el-form-item label="订单类型">
              <span>{{ props.row.orderType }}</span>
            </el-form-item>
            <el-form-item label="备注">
              <span>{{ props.row.note }}</span>
            </el-form-item>
            <el-form-item label="zfb订单">
              <span>{{ props.row.zfbId }}</span>
            </el-form-item>
            <el-form-item label="分销商ID">
              <span>{{ props.row.dtId }}</span>
            </el-form-item>
            <el-form-item label="授权杂费">
              <span>{{ props.row.otherFees }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column
        prop="date"
        header-align="center"
        align="center"
        label="预定时间"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="orderCode"
        header-align="center"
        align="center"
        label="订单编号"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="orderType"
        header-align="center"
        align="center"
        label="订单类型"
        :formatter="orderType"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="hotelName"
        header-align="center"
        align="center"
        label="酒店名称"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        :formatter="dateStr"
        header-align="center"
        align="center"
        label="入离时间"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="name"
        header-align="center"
        align="center"
        label="联系人"
        width="77"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="phone"
        header-align="center"
        align="center"
        label="联系电话"
        width="77"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="orderStatus"
        header-align="center"
        align="center"
        label="订单状态"
        width="77"
        :formatter="statusOrder"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="buyStatus"
        header-align="center"
        align="center"
        label="采购状态"
        :formatter="statusBuy"
        width="77"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        :formatter="buySource"
        prop="chanelCode"
        header-align="center"
        align="center"
        label="采购渠道"
        width="77"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="username"
        header-align="center"
        align="center"
        label="跟单人"
        width="77"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="77"
        label="跟单"
      >
        <template slot-scope="scope">
          <el-button
            :disabled="
              (scope.row.dealOrderPeo == null &&
                scope.row.orderStatus == 2 &&
                scope.row.orderType == 0) ||
              (scope.row.dealOrderPeo == null && scope.row.buyStatus == -1)
                ? false
                : true
            "
            v-if="isAuth('ord:order:lock')"
            size="small"
            type="primary"
            round
            @click="lockOrder(scope.row)"
            >跟单</el-button
          >
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="77"
        label="下单"
      >
        <template slot-scope="scope" :v-model="me">
          <el-button
            :disabled="
              (scope.row.buyStatus == 0 ||
                scope.row.buyStatus == -1 ||
                scope.row.buyStatus == 1) &&
              me == scope.row.dealOrderPeo &&
              scope.row.orderStatus == 2
                ? false
                : true
            "
            v-if="isAuth('ord:order:deal')"
            type="primary"
            round
            size="small"
            @click="dealWithOrder(scope.row)"
            >下单</el-button
          >
        </template>
      </el-table-column>

      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="77"
        label="发票"
      >
        <template slot-scope="scope">
          <el-button
            type="info"
            round
            v-if="isAuth('ord:order:invo')"
            size="small"
            @click="invo(scope.row)"
            >详情</el-button
          >
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="77"
        label="入住人"
      >
        <template slot-scope="scope">
          <el-button
            type="info"
            round
            size="small"
            v-if="isAuth('ord:order:peo')"
            @click="infoHandle(scope.row)"
            >详情</el-button
          >
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="77"
        label="备注"
      >
        <template slot-scope="scope">
          <el-button
            type="info"
            round
            size="small"
            v-if="isAuth('ord:order:peo')"
            @click="noteHandle(scope.row.id)"
            >备注</el-button
          >
        </template>
      </el-table-column>

      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="77"
        label="短信"
      >
        <template slot-scope="scope" :v-model="me">
          <el-button
            :disabled="scope.row.isMsg == 1 ? true : false"
            type="primary"
            round
            size="small"
            @click="sendMsg(scope.row)"
            >短信</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    >
    </el-pagination>
    <!-- 入住人详情 -->
    <peo-info v-if="infoVisible" ref="peoInfo"></peo-info>
    <!--弹窗，处理订单-->
    <deal-with v-if="dealWithVisible" ref="dealWith"> </deal-with>
    <!-- 发票详情 -->
    <invo v-if="invoVisible" ref="invo"> </invo>
    <!-- 备注 -->
    <note v-if="noteVisible" ref="note"></note>
  </div>
</template>

<script>
import PeoInfo from "./ordorder-peo-info";
import DealWith from "./ordorder-dealwith";
import Invo from "./ordorder-invo";
import Note from "./ordorder-note";
export default {
  data() {
    return {
      dataForm: {
        ordCode: "",
        dateTime: null,
        phone: "",
      },
      me: 0,
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      peoInfoVisible: false,
      dealWithVisible: false,
      infoVisible: false,
      invoVisible: false,
      noteVisible: false,
    };
  },
  components: {
    "peo-info": PeoInfo,
    "deal-with": DealWith,
    invo: Invo,
    note: Note,
  },
  activated() {
    this.getDataList();
  },
  methods: {
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("/ord/order/list"),
        method: "post",
        data: this.$http.adornData({
          page: this.pageIndex,
          limit: this.pageSize,
          ordCode: this.dataForm.ordCode,
          dateTime: this.dataForm.dateTime,
          phone: this.dataForm.phone,
        }),
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list;
          this.totalPage = data.page.totalCount;
          this.me = data.me;
          console.info(data);
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 采购渠道 1,携程 2，美团 3，人工线下采购 4，其他
    buySource(data) {
      let status = data.buySource;
      return status == 1
        ? "携程"
        : status == 2
        ? "美团"
        : status == 3
        ? "人工线下采购"
        : status == 4
        ? "其他"
        : "";
    },
    // 入住时间段
    dateStr(data) {
      return data.checkInDate + "~" + data.checkOutDate;
    },
    // 订单类型
    orderType(data) {
      let status = data.orderType;
      return status == 0 ? "人工订单" : status == 1 ? "直连订单" : "其他";
    },
    // 订单状态判断
    statusOrder(data) {
      let status = data.orderStatus;
      return status == "1"
        ? "未支付"
        : status == "2"
        ? "已支付"
        : status == "3"
        ? "已发货"
        : status == "4" //-1 申请退款 -2 已退款 -3关单
        ? "已入住"
        : status == "-1"
        ? "申请退款"
        : status == "-2"
        ? "已退款"
        : status == "-3"
        ? "关单"
        : "";
    },
    // 采购状态判断
    // 0未采购，1已受理（已提交）2已采购 -1 采购失败 -2 已退单
    statusBuy(data) {
      let status = data.buyStatus;
      return status == "0"
        ? "未采购"
        : status == "1"
        ? "已受理"
        : status == "3"
        ? "已采购"
        : status == "-1"
        ? "采购失败"
        : status == "-2"
        ? "退款失败"
        : "";
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    // 入住人详情页
    infoHandle(row) {
      this.infoVisible = true;
      this.$nextTick(() => {
        this.$refs.peoInfo.init(row.orderCode);
      });
    },
    // 备注页
    noteHandle(id) {
      this.noteVisible = true;
      this.$nextTick(() => {
        this.$refs.note.init(id);
      });
    },
    // 处理订单
    dealWithOrder(val) {
      this.$http({
        url: this.$http.adornUrl("/ord/order/deal"),
        method: "get",
        params: this.$http.adornParams({
          dealOrderPeo: val.dealOrderPeo,
          id: val.id,
          buyStatus: val.buyStatus,
          orderStatus: val.orderStatus,
        }),
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dealWithVisible = true;
          this.$nextTick(() => {
            this.$refs.dealWith.init(val.id);
          });
        } else {
          this.$message.error(data.msg);
        }
      });
    },
    // 退款
    sendMsg(val) {
      this.$confirm(`确定发送退款短信操作?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl("/ord/order/sendmsg"),
          method: "get",
          params: this.$http.adornParams({
            id: val.id,
          }),
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.getDataList();
            this.$message({
              message: data.msg,
              type: "success",
              duration: 1500,
            });
          } else {
            this.$message.error(data.msg);
          }
        });
      });
    },
    // 跟单
    lockOrder(val) {
      this.$http({
        url: this.$http.adornUrl("/ord/order/lock"),
        method: "get",
        params: this.$http.adornParams({
          id: val.id,
        }),
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.$message({
            message: "操作成功",
            type: "success",
            duration: 1000,
            onClose: () => {
              this.getDataList();
            },
          });
        } else {
          this.$message.error(data.msg);
        }
      });
    },
    // 发票信息
    invo(row) {
      this.invoVisible = true;
      this.$nextTick(() => {
        this.$refs.invo.init(row.orderCode);
      });
    },
  },
};
</script>
<style>
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>
